import { fromJS } from 'immutable';
import * as constants from './constants';

const defaultState = fromJS({
  organization: [],
  allUserData:[],
  currentToken:{},
  subFlag:0,
  userData:{},
  childAllData:{},
  childDataSource:{},
  parentRecord:{},
  orgPageNum:0,
  childPageNum:0
});

export default(state=defaultState, action) => {
  switch(action.type){
    case 'set_current_token':
      return state.merge({
        currentToken: action.currentToken,
      });
    case 'err_token':
      return state.set('currentToken',action.currentToken)
    // case constants.CHANGE_MENU:
    //   return state.set('currentMenu',action.current);
    case 'get_All_users':
      return state.merge({
        allUserData:action.AllUser,
        orgPageNum:action.orgPageNum
      })
    case 'back':
      return state.set('subFlag',action.flag);
    case 'enter_sub':
       return state.merge({
        subFlag:action.flag,
        parentRecord:action.parentRecord
       })
    case 'save_user_data':
      return state.set('userData',action.userData)
    case 'get_child_data':
      return state.merge({
        childPageNum:action.childPageNum,
        childDataSource:action.childDataSource
      })
    default: return state;

  }
}